import client.handler.SslChannelInitializer;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import java.io.FileInputStream;
import java.nio.channels.Channel;
import java.security.KeyStore;
import javax.net.ssl.TrustManagerFactory;

public class NettyClient {

  public static void main(String[] args) throws Exception {
    EventLoopGroup group;
    group = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(group).channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.SO_REUSEADDR, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);


    TrustManagerFactory tf = null;
    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream("D:/cChat.jks"), "cNetty".toCharArray());
    tf = TrustManagerFactory.getInstance("SunX509");
    tf.init(keyStore);
    SslContext sslContext = SslContextBuilder.forClient().trustManager(tf).build();

    b.handler(new SslChannelInitializer(sslContext));

    ChannelFuture future = b.connect("localHost",9912);
    future.channel().closeFuture().sync();
  }
}

